<?php

/**
 * 夏日葵电商系统
 * http://www.xiarikui.com
 */

namespace Admin\Controller;

class SpecialController extends BaseController {

    public function index() {
        $this->display();
    }

    /**
     * 专题
     */
    public function special() {
        $act = I('GET.act', 'add');
        $this->assign('act', $act);
        $special_id = I('GET.special_id');
        $special_info = array();
        if ($special_id) {
            $special_info = D('special')->where('special_id=' . $special_id)->find();
            $this->assign('info', $special_info);
        }

        $this->assign("URL_upload", U('Admin/Ueditor/imageUp', array('savepath' => 'special')));
        $this->assign("URL_fileUp", U('Admin/Ueditor/fileUp', array('savepath' => 'special')));
        $this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp', array('savepath' => 'special')));
        $this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage', array('savepath' => 'special')));
        $this->assign("URL_imageManager", U('Admin/Ueditor/imageManager', array('savepath' => 'special')));
        $this->assign("URL_imageUp", U('Admin/Ueditor/imageUp', array('savepath' => 'special')));
        $this->assign("URL_getMovie", U('Admin/Ueditor/getMovie', array('savepath' => 'special')));
        $this->assign("URL_Home", "");
        $this->display();
    }

    /**
     * 专题列表
     */
    public function specialList() {
        $specialMod = M('special');
        $res = $specialMod->where('1=1')->order('ctime')->page($_GET['p'] . ',10')->select();
        if ($res) {
            foreach ($res as $val) {
                $val['special_state'] = $val['special_state'] > 1 ? '已发布' : '未发布';
                $val['ctime'] = date('Y-m-d H:i', $val['ctime']);
                $list[] = $val;
            }
        }
        $this->assign('list', $list); 
        $count = $specialMod->where('1=1')->count();
        $Page = new \Think\Page($count, 10); 
        $show = $Page->show(); 
        $this->assign('page', $show);
        $this->display();
    }

    /**
     * 专题处理
     */
    public function specialHandle() {
        $specialMod = D('special');
        $data = I('post.');
        $data['special_content'] = $_POST['special_content'];         
        if ($data['act'] == 'add') {
            $data['ctime'] = time();
            $r = $specialMod->add($data);
        }
        if ($data['act'] == 'edit') {
            $r = $specialMod->where('special_id=' . $data['special_id'])->save($data);
        }

        if ($data['act'] == 'del') {
            $r = $specialMod->where('special_id=' . $data['special_id'])->delete();
            if ($r)
                exit(json_encode(1));
        }

        if ($r) {
            $this->success("操作成功", U('Admin/Special/specialList'));
        } else {
            $this->error("操作失败", U('Admin/Special/specialList'));
        }
    }

}
